#include "lolevel.h"
#include "platform.h"
#include "core.h"
#include "conf.h"

static long *nrflag = (long*)0xD1B4; 

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) sub_FFB2E77C_my(long p)
{
    asm volatile (
                "STMFD   SP!, {R4,LR}\n"
                "MOV     R4, R0\n"
                "SUB     SP, SP, #0xC\n"
                "BL      sub_FFB2F240\n"
                "MVN     R1, #0\n"
                "BL      sub_FFB403C8\n" //ClearEventFlag
                "MOV     R0, #0x8A\n"
                "ADD     R1, SP, #4\n"
                "MOV     R2, #4\n"
                "BL      sub_FF81BD58\n"
                "TST     R0, #1\n"
                "BEQ     loc_FFB2E7BC\n"
                "MOV     R1, #0x1D0\n"
                "LDR     R0, =0xFFB2E600\n" //=aSscaptureseq_c
                "ADD     R1, R1, #2\n"
                "BL      sub_FFB4D9F0\n" // DebugAssert
"loc_FFB2E7BC:\n"
                "LDR     R3, =0xB6FE0\n"
                "LDR     R2, =0xB70A0\n"
                "LDR     R0, [R3,#0x7C]\n"
                "LDRSH   R1, [R2,#0xE]\n"
                "BL      sub_FFA4D830\n" //nullsub_135
                "MOV     R0, R4\n"
                "BL      sub_FFB2E584\n" 
                "BL      wait_until_remote_button_is_released\n"
                "BL      capt_seq_hook_set_nr\n" // +
                "B       sub_FFB2E7D8\n"
    );
}

void __attribute__((naked,noinline)) sub_FFB2B154_my(long p)
{
    asm volatile (
                "STMFD   SP!, {R4,R5,LR}\n"
                "LDR     R1, =0xB6FE0\n"
                "LDR     R4, [R0,#0xC]\n"
                "LDR     R2, [R1,#0x24]\n"
                "LDR     R3, [R4,#8]\n"
                "CMP     R2, #0\n"
                "ORR     R3, R3, #1\n"
                "STR     R3, [R4,#8]\n"
                "BNE     loc_FFB2B1B4\n"
                "LDR     R3, [R1,#0xC]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FFB2B1B4\n"
                "MOV     R0, #0xC\n"
                "BL      sub_FFB360D8\n"
                "TST     R0, #1\n"
                "BEQ     loc_FFB2B1B4\n"
                "LDR     R3, [R4,#8]\n"
                "MOV     R0, #1\n"
                "ORR     R3, R3, #0x40000000\n"
                "STR     R3, [R4,#8]\n"
"loc_FFB2B1A4:\n"
                "MOV     R2, R4\n"
                "MOV     R1, #1\n"
                "LDMFD   SP!, {R4,R5,LR}\n"
                "B       sub_FFB29314\n"
"loc_FFB2B1B4:\n"
                "LDR     R1, =0xB6FE0\n"
                "MOV     R3, #0x8200\n"
                "LDRH    R2, [R1]\n"
                "ADD     R3, R3, #0xA\n"
                "CMP     R2, R3\n"
                "BEQ     loc_FFB2B200\n"
                "LDRH    R3, [R1,#0x88]\n"
                "CMP     R3, #3\n"
                "BEQ     loc_FFB2B200\n"
                "LDR     R3, [R4,#0xC]\n"
                "CMP     R3, #1\n"
                "BLS     loc_FFB2B200\n"
                "LDRH    R3, [R1,#0x86]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FFB2B200\n"
                "LDRH    R3, [R1,#0x82]\n"
                "CMP     R3, #2\n"
                "BNE     loc_FFB2B200\n"
                "BL      sub_FFB2C2BC\n"
"loc_FFB2B200:\n"
                "LDR     R1, =0xB6FE0\n"
                "MOV     R3, #0x8200\n"
                "LDRH    R2, [R1]\n"
                "ADD     R3, R3, #0xA\n"
                "CMP     R2, R3\n"
                "BEQ     loc_FFB2B248\n"
                "LDRH    R3, [R1,#0x88]\n"
                "CMP     R3, #3\n"
                "BEQ     loc_FFB2B248\n"
                "LDR     R3, [R4,#0xC]\n"
                "CMP     R3, #1\n"
                "BLS     loc_FFB2B248\n"
                "LDRH    R3, [R1,#0x86]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FFB2B248\n"
                "LDRH    R3, [R1,#0x82]\n"
                "CMP     R3, #2\n"
                "BEQ     loc_FFB2B2B0\n"
"loc_FFB2B248:\n"
                "LDR     R2, =0xB6FE0\n"
                "LDRH    R3, [R2,#0x88]\n"
                "CMP     R3, #3\n"
                "BEQ     loc_FFB2B2C8\n"
                "LDRH    R3, [R2,#0x86]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FFB2B2C8\n"
                "LDRH    R1, [R2,#0x82]\n"
                "CMP     R1, #1\n"
                "BNE     loc_FFB2B2C8\n"
                "LDRH    R2, [R2]\n"
                "MOV     R3, #0x8200\n"
                "ADD     R3, R3, #0xA\n"
                "CMP     R2, R3\n"
                "BEQ     loc_FFB2B2C8\n"
                "LDR     R3, [R4,#0xC]\n"
                "CMP     R3, #1\n"
                "BLS     loc_FFB2B2C8\n"
                "ADD     R3, R1, #0xFF00\n"
                "ADD     R3, R3, #0xFF\n"
                "MOV     R3, R3,LSL#16\n"
                "CMP     R3, #0x10000\n"
                "BHI     loc_FFB2B2C8\n"
                "LDR     R3, [R4,#0x10]\n"
                "CMP     R3, #1\n"
                "BNE     loc_FFB2B2C8\n"
"loc_FFB2B2B0:\n"
                "LDR     R3, =0x920D8\n"
                "MOV     R2, #0xEA00\n"
                "LDR     R0, [R3]\n"
                "MOV     R1, #0x40000000\n"
                "ADD     R2, R2, #0x60\n"
                "BL      sub_FFB3658C\n"
"loc_FFB2B2C8:\n"
                "LDR     R5, =0xB6FE0\n"
                "BL      sub_FFB2B034\n"
                "LDR     R3, [R5,#0x24]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FFB2B2E4\n"
                "MOV     R0, #2\n"
                "BL      sub_FFB05878\n"
"loc_FFB2B2E4:\n"
                "BL      sub_FFB2BE18\n"  // Set_CMD25Write_60
                "LDR     R3, [R4,#0x18]\n"
                "CMP     R3, #0\n"
                "BEQ     loc_FFB2B2F8\n"
                "BL      sub_FFBAD14C\n"
"loc_FFB2B2F8:\n"
                "LDR     R3, [R5,#0x24]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FFB2B338\n"
                "MOV     R0, R4\n"
                "BL      sub_FFB2D100\n"
                "TST     R0, #1\n"
                "BNE     loc_FFB2B1A4\n"
                "BL      sub_FF826F90\n"
                "BL      sub_FF81BF54\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FFB2E664\n"
                "BL      sub_FFB2F0AC\n"
                "MOV     R0, R4\n"
                "BL      sub_FFB2E77C_my\n"         //-------------->
                "BL      capt_seq_hook_raw_here\n"  // +
                "B       loc_FFB2B34C\n"
"loc_FFB2B338:\n"
                "LDR     R3, =0xD19C\n"
                "LDR     R2, [R3]\n"
                "CMP     R2, #0\n"
                "MOVNE   R0, #0x1D\n"
                "MOVEQ   R0, #0\n"
"loc_FFB2B34C:\n"
                "MOV     R1, #1\n"
                "MOV     R2, R4\n"
                "BL      sub_FFB29314\n"
                "BL      sub_FFB2EB4C\n"
                "CMP     R0, #0\n"
                "LDRNE   R3, [R4,#8]\n"
                "ORRNE   R3, R3, #0x2000\n"
                "STRNE   R3, [R4,#8]\n"
                "LDR     R3, [R4,#0x18]\n"
                "CMP     R3, #0\n"
                "BEQ     loc_FFB2B37C\n"
                "BL      sub_FFBAD178\n"
"loc_FFB2B37C:\n"
                "LDR     R2, =0xB6FE0\n"
                "LDRH    R3, [R2,#0x88]\n"
                "CMP     R3, #3\n"
                "LDMEQFD SP!, {R4,R5,PC}\n"
                "LDRH    R3, [R2,#0x86]\n"
                "CMP     R3, #0\n"
                "LDMNEFD SP!, {R4,R5,PC}\n"
                "LDRH    R3, [R2,#0x82]\n"
                "CMP     R3, #2\n"
                "LDMNEFD SP!, {R4,R5,PC}\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4,R5,LR}\n"
                "B       sub_FFB2C314\n"
    );
}

void __attribute__((naked,noinline)) capt_seq_task()
{
	asm volatile (
                "STMFD   SP!, {R4,LR}\n"
                "SUB     SP, SP, #4\n"
                "MOV     R4, SP\n"
                "B       loc_FFB2B924\n"
"loc_FFB2B794:\n"
                "LDR     R2, [SP]\n"
                "LDR     R3, [R2]\n"
                "MOV     R0, R2\n"
                "CMP     R3, #0x17\n"
                "LDRLS   PC, [PC,R3,LSL#2]\n"
                "B       loc_FFB2B8FC\n"
                ".long loc_FFB2B80C\n"
                ".long loc_FFB2B82C\n"
                ".long loc_FFB2B840\n"
                ".long loc_FFB2B854\n"
                ".long loc_FFB2B84C\n"
                ".long loc_FFB2B85C\n"
                ".long loc_FFB2B864\n"
                ".long loc_FFB2B870\n"
                ".long loc_FFB2B878\n"
                ".long loc_FFB2B884\n"
                ".long loc_FFB2B88C\n"
                ".long loc_FFB2B894\n"
                ".long loc_FFB2B89C\n"
                ".long loc_FFB2B8A4\n"
                ".long loc_FFB2B8AC\n"
                ".long loc_FFB2B8B8\n"
                ".long loc_FFB2B8C0\n"
                ".long loc_FFB2B8C8\n"
                ".long loc_FFB2B8D0\n"
                ".long loc_FFB2B8DC\n"
                ".long loc_FFB2B8E4\n"
                ".long loc_FFB2B8EC\n"
                ".long loc_FFB2B8F4\n"
                ".long loc_FFB2B90C\n"
"loc_FFB2B80C:\n"
                "BL      sub_FFB2BE40\n"
                "BL      shooting_expo_param_override\n"  // +
                "BL      sub_FFB28CF8\n"
                "LDR     R3, =0xB6FE0\n"
                "LDR     R2, [R3,#0x24]\n"
                "CMP     R2, #0\n"
                "BEQ     loc_FFB2B908\n"
                "BL      sub_FFB2B3BC\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B82C:\n"
                "BL      sub_FFB2B154_my\n"   //--------------->
"loc_FFB2B830:\n"
                "LDR     R2, =0xB6FE0\n"
                "MOV     R3, #0\n"
                "STR     R3, [R2,#0x24]\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B840:\n"
                "MOV     R0, #1\n"
                "BL      sub_FFB2C060\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B84C:\n"
                "BL      sub_FFB2BA10\n"
                "B       loc_FFB2B830\n"
"loc_FFB2B854:\n"
                "BL      sub_FFB2BDF8\n"
                "B       loc_FFB2B830\n"
"loc_FFB2B85C:\n"
                "BL      sub_FFB2BE08\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B864:\n"
                "BL      sub_FFB2BF58\n"
                "BL      sub_FFB28CF8\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B870:\n"
                "BL      sub_FFB2B494\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B878:\n"
                "BL      sub_FFB2BFC8\n"
                "BL      sub_FFB28CF8\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B884:\n"
                "BL      sub_FFB2BDF8\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B88C:\n"
                "BL      sub_FFB2D91C\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B894:\n"
                "BL      sub_FFB2DAF0\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B89C:\n"
                "BL      sub_FFB2DB84\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8A4:\n"
                "BL      sub_FFB2DC80\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8AC:\n"
                "MOV     R0, #0\n"
                "BL      sub_FFB2DEEC\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8B8:\n"
                "BL      sub_FFB2E090\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8C0:\n"
                "BL      sub_FFB2E12C\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8C8:\n"
                "BL      sub_FFB2E1EC\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8D0:\n"
                "BL      sub_FFB2C1E0\n"
                "BL      sub_FFB2AF14\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8DC:\n"
                "BL      sub_FFB2DDC0\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8E4:\n"
                "BL      sub_FFB2DE1C\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8EC:\n"
                "BL      sub_FFB2B034\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8F4:\n"
                "BL      sub_FFB253DC\n"
                "B       loc_FFB2B908\n"
"loc_FFB2B8FC:\n"
                "LDR     R0, =0xFFB2AC58\n"
                "MOV     R1, #0x4D0\n"
                "BL      sub_FFB4D9F0\n"
"loc_FFB2B908:\n"
                "LDR     R2, [SP]\n"
"loc_FFB2B90C:\n"
                "LDR     R3, =0x920D8\n"
                "LDR     R1, [R2,#4]\n"
                "LDR     R0, [R3]\n"
                "BL      sub_FFB4022C\n"
                "LDR     R0, [SP]\n"
                "BL      sub_FFB2AD48\n"
"loc_FFB2B924:\n"
                "LDR     R3, =0x920DC\n"
                "MOV     R1, R4\n"
                "LDR     R0, [R3]\n"
                "MOV     R2, #0\n"
                "BL      sub_FFB40944\n"
                "TST     R0, #1\n"
                "BEQ     loc_FFB2B794\n"
                "MOV     R1, #0x400\n"
                "LDR     R0, =0xFFB2AC58\n"
                "ADD     R1, R1, #2\n"
                "BL      sub_FFB4D9F0\n"
                "BL      sub_FFB41F08\n"
                "ADD     SP, SP, #4\n"
                "LDMFD   SP!, {R4,PC}\n"
	);
}

